import { GetanTableProps } from "../types"

/**
 * 支持显示序号
 */
export function useIndex(props: Ref<Partial<GetanTableProps>>) {
    const column = {
        key: "_index",
        title: "#",
        align: "center",
        fixed: "left",
        maxWidth: 50,
        width: 50,
        render: (_rowData: Recordable, rowIndex: number) => {
            return rowIndex + 1
        }
    }

    const indexColumn = computed(() => {
        const { useIndex } = unref(props)
        if (useIndex === true) {
            // 使用默认
            return { ...column }
        } else if (useIndex) {
            // 支持自定义
            return useIndex as Recordable
        }
        return false
    })

    return { indexColumn }
}
